using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using AvaloniaApplication1.Models;

namespace AvaloniaApplication1.IServices;

public interface IMqttDeviceManager
{
      /// <summary>
        /// 添加设备
        /// </summary>
        Task<bool> AddDeviceAsync(string deviceId, string server, int port, string username, string password, List<MqttTopicConfig> topicoptions,bool isConnected=false);
        
        /// <summary>
        /// 移除设备
        /// </summary>
        Task<bool> RemoveDeviceAsync(string deviceId);
        
        /// <summary>
        /// 连接设备
        /// </summary>
        Task<bool> ConnectDeviceAsync(string deviceId);
        
        /// <summary>
        /// 断开设备连接
        /// </summary>
        Task<bool> DisconnectDeviceAsync(string deviceId);
        
        /// <summary>
        /// 获取设备信息
        /// </summary>
        MqttDeviceModel? GetDevice(string deviceId);
        
        /// <summary>
        /// 获取所有设备
        /// </summary>
        IEnumerable<MqttDeviceModel> GetAllDevices();
        
        /// <summary>
        /// 检查设备是否存在
        /// </summary>
        bool ContainsDevice(string deviceId);
        
        /// <summary>
        /// 获取设备连接状态
        /// </summary>
        bool IsDeviceConnected(string deviceId);
        /// <summary>
        /// 订阅主题
        /// </summary>
        /// <param name="deviceId">设备ID</param>
        /// <param name="topic">主题</param>
        /// <param name="qos">QoS等级</param>
    
        Task<bool> AddTopic(string deviceId, string topic, int qos = 0,bool isSubscription = true, bool isPublish = false);
        /// <summary>
        /// 取消订阅主题
        /// </summary>
        /// <param name="deviceId">设备ID</param>
        /// <param name="topic">主题</param>

        Task<bool> UnsubscribeTopic(string deviceId, string topic);
        
        /// <summary>
        /// 设备状态变更事件
        /// </summary>
        event EventHandler<DeviceStatusEventArgs> DeviceStatusChanged;
        
        /// <summary>
        /// 设备数据接收事件
        /// </summary>
        event EventHandler<DeviceDataEventArgs> DeviceDataReceived;
    }
    
    /// <summary>
    /// 设备状态事件参数
    /// </summary>
    public class DeviceStatusEventArgs : EventArgs
    {
        public string DeviceId { get; }
        
        public bool IsConnected { get; }
        
        public DeviceStatusEventArgs(string deviceId,  bool isConnected)
        {
            DeviceId = deviceId;
       
            IsConnected = isConnected;
        }
    }
    
    /// <summary>
    /// 设备数据事件参数
    /// </summary>
    public class DeviceDataEventArgs : EventArgs
    {
        public string DeviceId { get; }
        public string Topic { get; }
        public string Payload { get; }
        /// <summary>
        /// 通用消息数据
        /// </summary>
        public MqttMessageDataModel MessageData { get; } 
        
        public DeviceDataEventArgs(string deviceId, string topic, string payload,MqttMessageDataModel messageDataModel)
        {
            DeviceId = deviceId;
            Topic = topic;
            Payload = payload;
            MessageData = messageDataModel;
        }
    }
